let OSS = require('ali-oss');

let client = new OSS({
  region: 'oss-cn-beijing',
  accessKeyId: 'LTAI8tg5JupiIKzl',
  accessKeySecret: 'gZPiUFdoXr7wOKreYOaeMBZbwbF4U1',
  bucket: 'zd20180520'
});

async function getDownhttp(objectName){
  //encodeURI()
  objectName =decodeURI(objectName)
  let name = objectName.split('.')[0];
  let type = objectName.split('.')[1];
  let url = await client.signatureUrl(objectName,{response:{'content-disposition': 'attachment; filename="' + name + '.' + type + '"'}});
  return  url;
}

async function get(objectName) {
  try {
    objectName = '1560138370970滴滴电子发票.pdf';
    let result = await client.get(objectName, 'd://a.pdf');
    console.log(result);
  } catch (e) {
    console.log(e);
  }
}




export default ({
  get: get,
  down:getDownhttp
})
